<?php
/**
 * represents a javascript based regular expression validator.
 */
fily_XMLConverter::registerNamespace('regularexpressionvalidator', fily_RegularExpressionValidator);
class fily_RegularExpressionValidator extends fily_Validator {
    /**
     * the regular expression
     * @var <type>
     */
    protected $regularExpression;

    /**
     *
     */
    public function __construct() {
        parent::__construct();
        $this->setErrorMessage('*');
    }


    /**
     * sets the regular expresion
     * @param string $regularExpression
     */
    public function setRegularExpression($regularExpression) {
        $this->regularExpression  = $regularExpression;
    }

    /**
     * returns the regular expression
     * @return <type>
     */
    public function getRegularExpression() {
        return $this->regularExpression;
    }

    /**
     * prepares the control for the html output
     */
    public function prepare() {
        parent::prepare();
        if($this->getControlToValidate()!=null){
            $code = sprintf("firelynx.RegularExpressionValidator('%s', '%s', '%s', '%s', %s, %s);", $this->getId(), $this->getControlToValidate()->getId(), $this->validationGroup,  $this->getDisplayStyle(), $this->getExecutionTime(),$this->regularExpression );
            fily_ClientCodeManager::addCode($code);
            fily_ClientCodeManager::useId($this->getId());
            fily_ClientCodeManager::useId($this->controlToValidate->getId());

        }
    }

       public function XMLAttributes(array $attributes, $innerValue) {
        foreach($attributes as $key => $value){
            switch ($key){
                case 'regularexpression':
                    $this->setRegularExpression($value);
                    unset($attributes[$key]);

            }
        }
        parent::XMLAttributes($attributes, $innerValue);
    }


    
}
?>
